package il.ac.bgu.soa2009.hw5.restuarnt;

import org.apache.log4j.Logger;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * User: Henry
 * Date: 23/02/2009
 * Time: 14:49:25
 */
public class MyDate {
    private static final DateFormat DATEFORMAT = new SimpleDateFormat("dd.MM.yyyy");
    private static final Logger logger = Logger.getLogger(MyDate.class);
    private GregorianCalendar date;

    public MyDate(Date date) {
        this.date = new GregorianCalendar();
        this.date.setTime(date);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        MyDate myDate = (MyDate) o;

        return !(date.get(GregorianCalendar.YEAR) != myDate.date.get(GregorianCalendar.YEAR) |
                date.get(GregorianCalendar.MONTH) != myDate.date.get(GregorianCalendar.MONTH) |
                date.get(GregorianCalendar.DAY_OF_MONTH) != myDate.date.get(GregorianCalendar.DAY_OF_MONTH));
    }

    @Override
    public int hashCode() {
        return date != null ? date.hashCode() : 0;
    }

    @Override
    public String toString() {
        return DATEFORMAT.format(date.getTime());
    }
}
